<template>
<view class="container">
    <!--轮播图-->
    <view class="header">
        <image :src="imgUrl+banner"></image>
    </view>
	<view class="header1">
		<view class="city" @click="jumpUrl('/pages/city/index')">
			<view>{{city}}</view>
			<image src="/static/img/address.png"  />
		</view>
		<view class="search">
			<icon size="14" type="search"></icon>
			<input :value="keyword" @input="search" placeholder="请输入机构名称"/>
		</view>
	</view>
    <view class="line">
        
    </view>
    <view class="body">
        <view class="newslist" v-for="(item,index) in school" :key="index" @click="jump(item.id)">
            <image v-if="item.imgs.length > 0" :src="imgUrl+item.imgs[0]" ></image>
            <image v-else :src="imgUrl+item.license" ></image>
            <view class="content">
                <view class="title">机构名称:<text class="name">{{item.name}}</text></view>
                <view class="title1">联系人:<text class="name">{{item.contacts}}</text></view>
                <view class="title1">客服电话:<text class="name">18322223377</text></view>
            </view>
        </view>
    </view>
</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			imgUrl:this.url,
			banner:'',
			school:[],
			totalPage:0,
			page:1,
			city:'全部',
			keyword:''
		}
	},
	onShow:function(){
		uni.showLoading({
		    title: '加载中'  
		});
		this.page = 1;
		this.totalPage = 0;
		this.getBanner();
		this.getSchool();
	},
	methods: {
		getBanner:function(){
			var that = this;
			var data = {'type':7}
			request({
				url: 'banner',
				method: 'get',
				data:data,
				success: (res) => {
					that.banner = res.data.data[0].img
				}
			})
		},
		getSchool:function(){
			var that = this
			if(this.city == '全部'){
				var city = '';
			}else{
				var city = this.city;
			}
			var data = {
				page:this.page,
				city:city,
				keyword:this.keyword
			}
			request({
				url: 'company/is_lease',
				method: 'get',
				data:data,
				success: (res) => {
					//请求成功
					if(res.data.code == 1){
					  if(that.totalPage == 0){
						  that.totalPage = res.data.data.last_page
					  }
					  uni.hideLoading()
					  if(that.page == 1){
						  that.school = res.data.data.data 
					  }else{
						 var school = that.school
						 that.school = school.concat(res.data.data.data)
					  }
					}
				}
			})
		},
		onReachBottom: function(){
			if(this.page < this.totalPage){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getSchool();
			}
		},
		jump:function(id){
			uni.navigateTo({
				url:'/pages/lease/info?id='+id
			});
		},
		jumpUrl:function(url){
			this.page = 1;
			uni.navigateTo({
				url:url
			});
		},
		search:function(e){
			this.keyword = e.detail.value
			this.page = 1;
			this.totalPage = 0;
			uni.showLoading({
			    title: '加载中'  
			});
			this.getSchool();
		}
	}
}
</script>
<style scoped>
	@import url("./css/index.css");
</style>
